function setHotList(data){
	var list=[]
	if(!localStorage.getItem("hotList")){
		localStorage.setItem("hotList", JSON.stringify(list));
	}
	
	list=localStorage.getItem("hotList")
	try{
		list=JSON.parse(list)
	}catch(e){
		console.log("设置点击排行错误！")
	}
	
	if(list.length!==undefined && data){
		var flag=false
		for(var i=0,j=list.length;i<j;i++){
			if(list[i] && data.title === list[i].title){
				flag=true
				list[i].weight=list[i].weight ? (list[i].weight-(-1)) : 1
				break
			}
		}
		if(!flag){
			data.weight=data.weight ? (data.weight-(-1)) : 1
			list.push(data)
		}
	}
	localStorage.setItem("hotList", JSON.stringify(list));
}
function getHotList(){
	var list=[]
	if(!localStorage.getItem("hotList")){
		return list
	}else{
		list=localStorage.getItem("hotList")
		try{
			list=JSON.parse(list)
		}catch(e){
			console.log("获取点击排行错误！")
		}
	}
	return list
}
function setCollection(data){
	var collection=[]
	var flag=false
	if(!localStorage.getItem("collection")){
		localStorage.setItem("collection", JSON.stringify(collection));
	}
	
	collection=localStorage.getItem("collection")
	try{
		collection=JSON.parse(collection)
	}catch(e){
		console.log("设置点击排行错误！")
	}
	
	for(var i=0,j=collection.length;i<j;i++){
		if(collection[i].title == data.title){
			flag=true
			break
		}
	}
	if(!flag){
		collection.push(data)
	}
	localStorage.setItem("collection", JSON.stringify(collection));
}
function getCollection(){
	var collection=[]
	if(!localStorage.getItem("collection")){
		return collection
	}else{
		collection=localStorage.getItem("collection")
		try{
			collection=JSON.parse(collection)
		}catch(e){
			console.log("获取收藏列表错误！")
		}
	}
	return collection
}
function jsonp(url,data,callback){
	var reData=""
	var callBackName="callback_"+(new Date-0)
	var script=document.createElement('script')
	    
		for(var key in data){
			reData+=(key+'='+data[key]+'&')
		}
		
		window[callBackName]=function(data){
			callback(data)
			delete window[callBackName]
		}
		
	    script.src=url+'?'+reData+'callback='+callBackName
		document.getElementsByTagName('body')[0].appendChild(script)
	    script.onload=function(){
			script.remove()
		}
		script.onerror=function(){
			script.remove()
		}
}

export { setHotList, getHotList,setCollection,getCollection,jsonp }